package com.unicom.auth.controller;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import com.jfinal.aop.Clear;
import com.unicom.auth.controller.base.BaseController;
import com.unicom.auth.interceptor.AuthorizationInterceptor;
import com.unicom.auth.kit.SessionKits;
import com.unicom.auth.model.Menu;
import com.unicom.auth.model.Resource;
import com.unicom.auth.model.User;
@Clear(AuthorizationInterceptor.class)
public class MenuController extends BaseController {

	@Override
	public void index() {
		// TODO Auto-generated method stub

	}
	
	
	public void show() throws Exception{
		User user=SessionKits.getUser(this);
		List<Resource> menus=Resource.dao.findMenus(user);
		List<String> menuCodes=new ArrayList<>();
		for (Resource resource : menus) {
			menuCodes.add(resource.getCode());
		}
		if(!menuCodes.contains(getPara(0))){
			throw new Exception("越权访问");
		}
		Resource resource=Resource.dao.findById(getPara(0));
		Resource pResource=Resource.dao.findById(resource.getPCode());
		setAttr("menu", resource);
		setAttr("pMenu", pResource);
		myRender(resource.getPatternUrl());
	}
	
	
	

}
